import pymysql

row = []
with open("/home/u/Downloads/dict.txt") as f:
    for line in f:
        word, exp = line.split(" ", 1)
        row.append((word, exp.strip()))

db = pymysql.connect(user="devil", password="123456", database="dict", charset="utf8")
cur = db.cursor()

try:
    sql = 'insert into mydict (word, exp) values (%s, %s)'
    cur.executemany(sql, row)
except Exception as e:
    print(e)
    db.rollback()
else:
    db.commit()

cur.close()
db.close()
